import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { API_DOMAIN } from './constants'

console.log('使用API域名:', API_DOMAIN);

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  server: {
    proxy: {
      '/api': {
        target: `http://${API_DOMAIN}`,
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path,
        configure: (proxy, _options) => {
          proxy.on('error', (err, _req, _res) => {
            console.log('代理错误:', err);
          });
          proxy.on('proxyReq', (proxyReq, req, _res) => {
            console.log('代理请求:', req.method, req.url, '->',
                         proxyReq.method, proxyReq.protocol, proxyReq.host, proxyReq.path);
          });
          proxy.on('proxyRes', (proxyRes, req, _res) => {
            console.log('代理响应:', proxyRes.statusCode, req.url);
          });
        }
      }
    },
    allowedHosts: [
      'localhost',
      'bjl.teastonetravel.vip',
      API_DOMAIN
    ]
  }
}) 